package com.atguigu.lease.web.admin.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.atguigu.lease.model.entity.AttrKey;
import com.atguigu.lease.model.entity.AttrValue;
import com.atguigu.lease.model.entity.FeeKey;
import com.atguigu.lease.model.entity.FeeValue;
import com.atguigu.lease.web.admin.mapper.FeeKeyMapper;
import com.atguigu.lease.web.admin.service.FeeKeyService;
import com.atguigu.lease.web.admin.vo.attr.AttrKeyVo;
import com.atguigu.lease.web.admin.vo.fee.FeeKeyVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author liubo
* @description 针对表【fee_key(杂项费用名称表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class FeeKeyServiceImpl extends ServiceImpl<FeeKeyMapper, FeeKey>
    implements FeeKeyService{

    @Override
    public List<FeeKeyVo> selectALL() {
        List<FeeKey> list1=list();
        List<FeeValue> list2 = Db.lambdaQuery(FeeValue.class).list();
        Map<Long, List<FeeValue>> listMap=new HashMap<>();
        //把vo分组变成id的map集合
        if(CollUtil.isNotEmpty(list2))
        {
            listMap = list2.stream().collect(Collectors.groupingBy(FeeValue::getFeeKeyId));
        }
        List<FeeKeyVo> vo=new ArrayList<>();
        for (FeeKey feeKey : list1) {
            FeeKeyVo v=new FeeKeyVo();
            v.setName(feeKey.getName());
            v.setId(feeKey.getId());
            v.setFeeValueList(listMap.get(feeKey.getId()));
            vo.add(v);
        }
        return vo;
    }
}




